﻿@model Refactored.Models.LoginModel

@functions{
    public string GetAntiForgeryToken()
    {
        string cookieToken, formToken;
        AntiForgery.GetTokens(null, out cookieToken, out formToken);
        return cookieToken + ":" + formToken;
    }
}
<div>
    @if (@User.Identity.IsAuthenticated)
    {
        <input id="antiForgeryToken" type="hidden" value="@GetAntiForgeryToken()" />
        <div id="outer-container">
            <div id="sideBar">
                <div>
                    <ul id="menu">
                        <li id="homeLi">@Html.ActionLink("NetBooks", "Index", "Home", new { area = "" }, null)</li>
                        <!-- ko foreach: views -->
                        <li data-bind="text: $data, css: { selected: $data == $root.chosenView() }, click: $root.goToView"></li>
                        <!-- /ko -->
                        <li id="searchLi">search box goes here</li>
                        @*<li id="addLi" data-bind="click: addBook">Add New Book</li>*@
                    </ul>
                </div>
            </div>

            <div id="main-content">
                <header>
                    <h1 data-bind="text: chosenView" />
                </header>
                <!-- Mails grid -->
                <table class="books" data-bind="visible: chosenViewData">
                    <thead>
                        <tr>
                            <th>Title</th>
                            <th>Author</th>
                            <th>Genre</th>
                            <th>Rating</th>
                        </tr>
                    </thead>
                    <tbody data-bind="foreach: chosenViewData">
                        <tr data-bind="click: $root.goToBook">
                            <td data-bind="text: title"></td>
                            <td data-bind="text: author"></td>
                            <td data-bind="text: genre"></td>
                            <td data-bind="text: rating"></td>
                        </tr>
                    </tbody>
                </table>

                <!-- Chosen mail -->
                <div data-bind="visible: !isEditing()">
                    <div class="viewBook" data-bind="with: chosenBookData">
                        <div class="bookInfo">
                            <h1 data-bind="text: title"></h1>
                            <p><label>Author</label>: <span data-bind="text: author"></span></p>
                            <p><label>Genre</label>: <span data-bind="text: genre"></span></p>
                            <p><label>Rating</label>: <span data-bind="text: rating"></span></p>
                            <label>Description</label>
                            <p class="description" data-bind="html: description" />
                        </div>
                        <a href="#" data-bind="click: $parent.editBook">Edit</a>
                        <span> | </span>
                        <a href="#" data-bind="click: $parent.returnToList">Back to list</a>
                    </div>
                </div>
                <div data-bind="visible: isEditing()">
                    <div class="viewBook" data-bind="with: chosenBookData">
                        <div class="bookInfo">
                            <h1><input data-bind="value: title" /></h1>
                            <p><label>Author</label>: <input data-bind="value: author" /></p>
                            <p><label>Genre</label>: <input data-bind="value: genre" /></p>
                            <p><label>Rating</label>: <input data-bind="value: rating" /></p>
                            <label>Description</label>
                            <textarea data-bind="value: description"></textarea>
                        </div>
                        <a href="#" data-bind="click: $parent.saveBook" alt="Save the book">Save</a>
                    </div>
                </div>
            </div>
        </div>
    }
    else
    {
        <div class="todoList" id="loginPanel">
            <section id="localLoginPanel">
                <h2>Log in</h2>
                @Html.Partial("_Login")
            </section>
            <p>First time here? <a id="showRegister">Sign up</a></p>
        </div>
        <div class="todoList" id="registerPanel">
            <h2>Sign up</h2>
            @Html.Partial("_Register")
            <p>Already signed up? <a id="showLogin">Log in</a></p>
        </div>
    }
</div>

@if (@User.Identity.IsAuthenticated)
{
    @section scripts {
        @Scripts.Render("~/bundles/knockout")
        @Scripts.Render("~/bundles/jqueryval")
        @Scripts.Render("~/bundles/netbooks")
    }
}